package com.ophiux.cs.application.consultBase.impl;

import com.ophiux.cs.application.consultBase.dto.UpdateDoctorRequest;
import com.ophiux.cs.application.consultBase.dto.UpdateDoctorResponse;
import com.ophiux.cs.application.consultBase.service.IUpdateDoctorAppService;
import com.ophiux.cs.application.consultBase.service.IUpdateHospitalAppService;
import com.ophiux.cs.application.core.AppResultCode;
import com.ophiux.cs.application.core.Result;
import com.ophiux.cs.application.core.ResultEnum;
import com.ophiux.cs.domain.consultBase.model.entity.Doctor;
import com.ophiux.cs.domain.consultBase.repositories.IDoctorRepository;
import com.ophiux.utils.common.ShiftUtils;
import com.ophiux.utils.exception.OphiuxRepositoryException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UpdateDoctorAppService implements IUpdateDoctorAppService {

    @Autowired
    IDoctorRepository doctorRepositories;

    @Override
    public Result<UpdateDoctorResponse> updateDoctor(UpdateDoctorRequest dto) {
        UpdateDoctorResponse resp = new UpdateDoctorResponse();
        //验证参数是否允许为空
        if(!dto.isParamValid()) {
            return Result.fail(ResultEnum.requestParamFail.getCode(), ResultEnum.requestParamFail.getMsg());
        }
        try {
            Doctor dos = null;
            dos = (Doctor) ShiftUtils.objToNewObj(dto, Doctor.class);
            try {
                //更新医院信息
                doctorRepositories.updateDoctor(dos);
            } catch (OphiuxRepositoryException e) {
                e.printStackTrace();
                return Result.fail(ResultEnum.requestException.getCode(), e.getExceptionMessage());
            }
        } catch (Exception e) {
            log.info("updateDoctor接口异常：",e);
            e.printStackTrace();
            return Result.fail(AppResultCode.EXCEPTION, "程序异常");
        }
        return Result.success(resp, "更新医生成功");
    }

  }
